package com.kaoshi.myweb.webtest.java.generics;

import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javassist.expr.NewArray;

import com.kaoshi.myweb.webtest.entity.Apple;
import com.kaoshi.myweb.webtest.entity.Fruit;

public class GenericTest2 {

	public static void main(String[] args) throws ParseException {
		Pair<String> pair = new Pair<String>("1", "2");
		String second = pair.getSecond();

		// pair.getSecond();的jvm 指令
		// 对原始方式pair.getSecond()的调用；
		// 将返回的Object类型强制转换为 String类型
		
		Pair<Integer> pair2 = new Pair<Integer>(1, 2);
		System.out.println(pair.getClass());
		System.out.println(pair2.getClass());
		System.out.println(pair.getClass() == pair2.getClass());
		
		//参数化 类型 的数组不合法
		//Pair<String>[] aPairs = new Pair<String>[];
		Pair[] pairs = new Pair[3];
		pairs[0] = new Pair<Integer>(1, 3);
		
		
		Pair<Fruit> fPair = new Pair<Fruit>(new Fruit(), new Fruit());
		//cannot convert from Pair<Fruit> to Pair<Apple>
		//Pair<Apple> aPair = fPair;
	}

	public static <T extends Comparable & Serializable> void min(T[] a) {
		T smallest = a[0];
		for (int i = 0; i < a.length; i++) {
			if (smallest.compareTo(a[i]) > 0)
				smallest = a[i];
		}
	}
}
